// 初始化配置
require(["../../config"], function(){

    // select2.css
    require(["css!select2-master/dist/css/select2.min.css"]);
    require(["css!select2-bootstrap-theme-master/dist/select2-bootstrap.min.css"]);
//    require(["css!datetimepicker/bootstrap-datetimepicker.css"]);

    // 美化<select>
    // require(["jquery", "select2"], function($) {
    //     $("select.select2").select2({
    //         // "placeholder": "请选择",
    //         "theme": "bootstrap"
    //     });
    //     $(window).resize(function() {
    //         $("select.select2").select2({
    //             "theme": "bootstrap"
    //         });
    //     });
    //  });
    
	// dataPicker
	require(["jquery", "datetimepicker"], function($) {
		$(".datepicker").datetimepicker({
			format: 'yyyy-mm-dd hh:ii', 
		    autoclose: true,
		    todayBtn: true
		});
	});

    // 其他
    require(["jquery", "bootstrap"], function($) {
        // 代码...
        $("body").fadeIn(1000);

        document.oncontextmenu = function(){ return false; }
        document.onkeydown = function(event){
        var e = event || window.event || arguments.callee.caller.arguments[0];
	        if(e && e.keyCode==116){
	            return false;
	        }
	    }
	    
        function activity_change(id){
        	var activity_id = 0;
        	if(id > 0){
            	$('#activity_id').val(id);
        		activity_id = id
        	}else{
        		activity_id = $('#activity_id').val();
        	}
        	if(activity_id > 0){
                $.post(URL.shop_list, { activity_id : activity_id } , function(json) {
                    if (0 == json.status) {
                        alert(json.info);
                    } else {
                        $('#shop_id').html(json.info).attr('disabled', false);
                    }
                }, "json");
            }else{
                $('#shop_id').html('<option>选择店铺</option>').attr('disabled', true);
            }
        }
        
	    $(function(){
	    	var width = $(window).width();
	        var index = 0;
	        //店铺选择/状态选择
	        $('#activity_id,#shop_id,input[name="order_status"]').change(function(){
	        	jump_index = -1;
	        	if(this.name == 'activity_id'){
	    	        activity_change(this.value);
	        	}
	        });
	        //搜索
	        $('#search').click(function(){
	            var activity_id = $('#activity_id').val();
	            if(activity_id == null || activity_id == 0){
	                alert('请选择活动');
	                return false;
	            }
	            if(index == 1){
	                return false;
	            }
	            if($('#paper_order').val() != '' || jump_index == -1){
	            	$('#page').val(0);
	            }
	            index = 1;
	            $('#list_title,#list_body,#list_body_page').hide();
	            $('#loading').show();
	            $.post(URL.get_list, $('form').serialize(), function(json) {
	                if(json.status == 1){
	                    var html = '';
	                    var data = json.info.list;
	                    for(i in data){
	                        var n = (parseInt(i) + 1);
	                        html += '<tr><td class="phone_hide">' + n + '</td>' + 
	                            '<td class="phone_hide">' + data[i]['order_id'] + '</td>' +
	                            '<td>' + data[i]['paper_order'] + '</td>' +
	                            '<td class="phone_hide">' + data[i]['shop_name'] + '</td>' +
	                            //'<td class="phone_hide">' + data[i]['conf_category'] + '</td>' +
	                            '<td>' + data[i]['order_amount'] + '</td>' +
	                            '<td class="phone_hide">' + data[i]['phone_number'] + '</td>' +
	                            '<td class="phone_hide">' + data[i]['create_time'] + '</td>' +
	                            '<td class="phone_hide"><font color="red">' + data[i]['apply_time'] + '</font></td>' +
	                            '<td class="phone_hide"><font color="green">' + data[i]['back_time'] + '</font></td>' +
	                            '<td>' + data[i]['order_status'] + '</td>';
	                        if(data[i]['order_status_id'] == 2 || data[i]['order_status_id'] == 4){
	                            html += '<td><a href="javascript:void(0);" onclick="apply(' + data[i]['order_id'] + ',' + data[i]['paper_order'] + ')">申请返款</a></td></tr>';
	                        }else{
	                            html += '<td><font color="#cccccc">申请返款</font></td></tr>'
	                        }
	                    }
	                    $('#no_list').hide();
	                    $('#loading').hide();
	                    $('#list_title').show();
	                    if(json.info.page){
	                        $('#list_body_page').html(json.info.page).show();
	                    }
	                    $('#list_body').html(html).show();
	                    //手机版隐藏字段
	                    if(width < 800){
	        	    		$('.phone_hide').hide();
	        	    	}
	                }else{
	                    $('#no_list').show();
	                    $('#loading').hide();
	                }
	                index = 0;
	            }, "json");
	        });
	    	//默认加载
	        //activity_change(21);
	    	//$('#search').trigger('click');
	    });
    });
});

